package com.southminority.ethnic.service.course.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.southminority.ethnic.pojo.CourseTeacher;
import com.southminority.ethnic.mapper.course.CourseTeacherMapper;
import com.southminority.ethnic.service.course.CourseTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author ASHTR
* @description 针对表【course_teacher(课程讲师表)】的数据库操作Service实现
* @createDate 2025-01-20 10:00:00
*/
@Service
public class CourseTeacherServiceImpl extends ServiceImpl<CourseTeacherMapper, CourseTeacher> implements CourseTeacherService {

    @Override
    public Page<CourseTeacher> getTeacherPageWithKeyword(Page<CourseTeacher> page, String keyword) {
        LambdaQueryWrapper<CourseTeacher> wrapper = new LambdaQueryWrapper<>();
        
        // 如果有关键词，进行模糊查询
        if (StringUtils.hasText(keyword)) {
            wrapper.like(CourseTeacher::getTeacherName, keyword)
                    .or()
                    .like(CourseTeacher::getTeacherPosition, keyword);
        }
        
        // 按创建时间倒序排列
        wrapper.orderByDesc(CourseTeacher::getCreateTime);
        
        return this.page(page, wrapper);
    }
} 